package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.controller.es.EsUnService;
import com.ruoyi.system.controller.es.dto.EsSearch;
import com.ruoyi.system.domain.vo.web.HomeProjectWebVo;
import com.ruoyi.system.domain.vo.web.WebProjectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.FyProjectMapper;
import com.ruoyi.system.domain.FyProject;
import com.ruoyi.system.service.IFyProjectService;

/**
 * 项目Service业务层处理
 *
 * @author ruoyi
 * @date 2025-06-05
 */
@Service
public class FyProjectServiceImpl implements IFyProjectService
{
    @Autowired
    private FyProjectMapper fyProjectMapper;
    @Autowired
    private EsUnService esUnService;
    @Autowired
    private RuoYiConfig ruoYiConfig;
    /**
     * 查询项目
     *
     * @param projectId 项目主键
     * @return 项目
     */
    @Override
    public FyProject selectFyProjectByProjectId(Long projectId)
    {
        return fyProjectMapper.selectFyProjectByProjectId(projectId);
    }

    /**
     * 查询项目列表
     *
     * @param fyProject 项目
     * @return 项目
     */
    @Override
    public List<FyProject> selectFyProjectList(FyProject fyProject)
    {
        return fyProjectMapper.selectFyProjectList(fyProject);
    }
    @Override
    public List<FyProject> selectFyProjectList2(FyProject fyProject)
    {
        return fyProjectMapper.selectFyProjectList2(fyProject);
    }

    @Override
    public List<HomeProjectWebVo> selectFyProjectListHome() {
        return fyProjectMapper.selectFyProjectListHome();
    }

    @Override
    public List<WebProjectVo> selectWebProject(String projectName,String projectType,String projectLevel) {
        return fyProjectMapper.selectWebProject( projectName, projectType, projectLevel);
    }

    /**
     * 新增项目
     *
     * @param fyProject 项目
     * @return 结果
     */
    @Override
    public int insertFyProject(FyProject fyProject)
    {

        fyProject.setIsDelete(0l);
        fyProject.setCreateTime(DateUtils.getNowDate());
        return fyProjectMapper.insertFyProject(fyProject);
    }

    /**
     * 修改项目
     *
     * @param fyProject 项目
     * @return 结果
     */
    @Override
    public int updateFyProject(FyProject fyProject)
    {

        fyProject.setUpdateTime(DateUtils.getNowDate());
        return fyProjectMapper.updateFyProject(fyProject);
    }

    /**
     * 批量删除项目
     *
     * @param projectIds 需要删除的项目主键
     * @return 结果
     */
    @Override
    public int deleteFyProjectByProjectIds(Long[] projectIds)
    {
        for (Long l:projectIds){
            FyProject fyProject=new FyProject();
            fyProject.setProjectId(l);
            fyProject.setIsDelete(1l);
            fyProjectMapper.updateFyProject(fyProject);
            EsSearch esSearch=new EsSearch();
            esSearch.setId(fyProject.getProjectId());
            esSearch.setLanmu("资源-项目名录");
            esSearch.setLanmuId(1);

            esUnService.delete(esSearch);
        }

        return 1;
    }

    /**
     * 删除项目信息
     *
     * @param projectId 项目主键
     * @return 结果
     */
    @Override
    public int deleteFyProjectByProjectId(Long projectId)
    {
        return fyProjectMapper.deleteFyProjectByProjectId(projectId);
    }
}
